﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace sp500
{
    class HistoryCSVParsing
    {
        private string m_csvdata;
        private Sp500QuteHistoryList m_historyQuteList=null;
        private string companySymbol;

        public HistoryCSVParsing(string csvdata,string symbol)
        {
            m_csvdata = csvdata;
            //m_historyQuteList = historyQuteList;
            companySymbol = symbol;
        }

        public void perform()
        {
            string[] row = m_csvdata.Split('\n');


            m_historyQuteList = new Sp500QuteHistoryList(companySymbol);
            // begin from 1 
            // the 0 is the csv table field header
            for (int i = 1; i < row.Length; i++ )
            {
                Sp500Dailyquote qute = new Sp500Dailyquote();

                string[] cols = row[i].Split(',');
                
                if (cols.Length==7)
                {
                    qute.TransationdataStringTX = cols[0];
	                qute.OpenpriceTX = Convert.ToDouble(cols[1]);
	                qute.HighpriceTX = Convert.ToDouble(cols[2]);
	                qute.LowpriceTX = Convert.ToDouble(cols[3]);
	                qute.ClosepriceTX = Convert.ToDouble(cols[4]);
	                qute.VolumeSizeTX = Convert.ToInt32(cols[5]);
	                qute.AdjClosePriceTX = Convert.ToDouble(cols[6]);

                    m_historyQuteList.addDailyQute(qute);
                } 
                else
                {
                    continue;
                }
            }

            
        }

        public Sp500QuteHistoryList getHistoryData()
        {
            return m_historyQuteList;
        }
    }
}
